#pragma once

class CLayoutGroup;

class CLayoutHierarchyBuilder
{
public:
	~CLayoutHierarchyBuilder();

	// order classes in a parent->children order to make the IsA call easier
	bool ReindexClasses( const CLayoutDefinition& layout );

private:
	struct GroupInfo
	{
		CLayoutGroup*					m_group;
		std::vector< GroupInfo* >		m_children;

		GroupInfo( CLayoutGroup* group )
			: m_group( group )
		{}

		void AddChildren( GroupInfo* otherGroup )
		{
			if ( m_children.end() == std::find( m_children.begin(), m_children.end(), otherGroup ) )
				m_children.push_back( otherGroup );
		}	
	};

	std::vector< GroupInfo* >			m_groups;

	// create wrapper for given group
	GroupInfo* GetWrapper( const CLayoutGroup* group );

	// create wrapper and export dependencies
	void AddGroup( const CLayoutGroup* group );

	// process the groups
	void WalkClassTree( GroupInfo* group, int& index );
};